
ALTER  proc sp_get_ps_line_item_gp_vendorId
(
	@CSLIT_ID numeric,
	@gp_vendorId INT OUT
)
as
begin

declare @customer_shipping_id int
declare @vendorId int
declare @location_address_id int
declare @from_address_id int


--select CustomerShipping_Id from Customer_Shipping_Line_Item_Table where CSLIT_ID = 671
select @customer_shipping_id = CustomerShipping_Id from Customer_Shipping_Line_Item_Table where CSLIT_ID = @CSLIT_ID

--Retreiving the vendor name
select @from_address_id = CST_From_Address_ID, @location_address_id = CST_Location_Address_ID from customer_shipping_table where CustomerShipping_ID = @customer_shipping_id

if( @location_address_id is null )
begin
	select @vendorId = RTRIM( Vendor_ID ) from Location where Address_Id = @from_address_id and Location.L_Type = 'Finished Goods'
end
else
begin
	select @vendorId = RTRIM( Vendor_ID ) from Location where Address_Id = @location_address_id and Location.L_Type = 'Finished Goods'
end

if @vendorId is not null
begin
	select @gp_vendorId = GP_Vendor_Id from CT_GP_Vendor_Mapping where CT_Vendor_Id = @vendorId
end

end --End of proc
